jQuery.noConflict();
(function($){
	jQuery(document).ready(function(){		
		function imagesSlider(){
			var container = jQuery('#banner');
			if(container.length == 0) return;
			var prev = container.find('.btnPrev');
			var next = container.find('.btnNext');
			var slideObj = jQuery('#homeSlider > div > ul');
			
			var arrImgs = jQuery('#homeSlider > div > ul > li');
			var arrTexts = jQuery('#bannerLeft > ul > li');
			arrTexts.fadeOut();
			jQuery(arrTexts[0]).fadeIn();
			//var visualSlider = jQuery('#campainVisual');
			var _WIDTH = 124;
			var _LENGTH = 3;
			var isClick = true;
			var currentIndex = 0;
			var currentText = 0;
			jQuery(slideObj.find('a')[0]).addClass('active');
			arrImgs.each(function(index, li ){
				jQuery(li).find('a').bind('click', function(e){
					 jQuery(arrTexts[currentText]).fadeOut('slow', function() {
						jQuery(arrTexts[index]).fadeIn();
						jQuery(arrImgs[index]).find('a').addClass('active');
						currentText = index;
					});
					return false;
				});
			});
			prev.bind("click", function(evt) {
				showImage(currentImage - 1);
				return false;
			});
			
			next.bind("click", function(evt) {		
				showImage(currentImage + 1);
				return false;
			});
			
			var isMoving = false;
			var currentImage = 0;
			
			function imgFade(img, li){
				jQuery(img).animate({
					'opacity': 0
					},500, function(){
						isClick = true;
						jQuery(img).attr('src', jQuery(li).find('a').attr('href'));
						jQuery(img).load(function(){
							jQuery(img).animate({
								'opacity': 1
							}, 500);
						});
						
				});
				arrImgs.each(function(index, item ){
					jQuery(item).find('a').removeClass('active');
					jQuery(li).find('a').addClass('active');
				});
			}
			
			function showImage(index) {
				if (index < 0 || index >= arrImgs.length - (_LENGTH - 1)) {
					return;
				}
				
				if (isMoving) {
					return;
				}
				isMoving = true;
				
				currentImage = index;
				if (currentImage > 0) {
					prev.css({
						opacity: 1,
						cursor: 'pointer'
					});
				} else {
					prev.css({
						opacity: 0.4,
						cursor: 'default'
					});
				}
				
				if (currentImage <= arrImgs.length - (_LENGTH + 1)) {				
					next.css({
						opacity: 1,
						cursor: 'pointer'
					});
				} else {
					next.css({
						opacity: 0.4,
						cursor: 'default'
					});
				}
				
				slideObj.animate({
					"margin-left": -currentImage * _WIDTH
				}, 500, function(){
					isMoving = false;
				});
			}
			showImage(0);
			
		}
		imagesSlider();
	});
})(jQuery);
//////////////////////